home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93a.txt
/
000066_icon-group-sender _Sun Feb 14 17:28:21 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1993-04-21
|
2KB
Received: by cheltenham.cs.arizona.edu; Sun, 14 Feb 1993 16:48:37 MST
Date: Sun, 14 Feb 93 17:28:21 CST
From: "Richard L. Goerwitz" <goer@midway.uchicago.edu>
Message-Id: <9302142328.AA06789@midway.uchicago.edu>
To: icon-group@cs.arizona.edu
Subject: novicy question
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
> I am trying to write a procedure that given a string looks to see
> if there are any curly braces and cuts out whatever is between them.
>
> procedure foo (line)
>
> line_ptr := 0 # initialize a line ptr
> com_set := '{}' # establish a cset of the things of interest
> line ? {
> if not find(com_set)
> then return line # if there is no curly return it
> else {
> temp := inline(tab(upto(comset))) #scissor out
> return temp # the stuff between curlies
> }
> }
>end # foo
The short answer is that you should just try
local s2
s2 := ""
s ? {
while s2 ||:= tab(find("{")) do {
move(1)
tab(find("}")+1)
}
s2 ||:= tab(0)
}
return s2
But this assumes that braces are never nested (as in "hello { the { re } }").
If the braces can be nested, then read up on how to use bal(). If this func-
tion is difficult for you to learn to use, then join the club :-), and post
again with with other questions. There's no rule against asking beginners'
questions here! Actually, they tend to spawn some interesting discussions.
If you're taking an introductory CS course, watch out. Your profs may be ex-
pecting you to handle (in addition to nesting) cases where the input is er-
roneous, i.e. "hello { there " (i.e. with no right brace). You might as well
be warned now, and not have to submit to this rite of passage :-). After all,
you get browny points for finding out about and using this mailing list.
-Richard Goerwitz